import 'package:amap_flutter_base/amap_flutter_base.dart';

class Location {
  String? locTime;
  String? province;
  String? callbackTime;
  String? district;
  String? country;
  String? street;
  num? speed;
  String? latitude;
  String? city;
  String? streetNumber;
  num? bearing;
  String? accuracy;
  String? adCode;
  num? altitude;
  num? locationType;
  String? longitude;
  String? cityCode;
  String? address;
  String? description;

  LatLng get position {
    return LatLng(double.parse(latitude ?? '39.909187'),
        double.parse(longitude ?? '116.397451'));
  }

  Location({
    this.locTime,
    this.province,
    this.callbackTime,
    this.district,
    this.country,
    this.street,
    this.speed,
    this.latitude,
    this.city,
    this.streetNumber,
    this.bearing,
    this.accuracy,
    this.adCode,
    this.altitude,
    this.locationType,
    this.longitude,
    this.cityCode,
    this.address,
    this.description,
  });

  factory Location.fromJson(Map<String, dynamic> json) => Location(
        locTime: json['locTime'] as String?,
        province: json['province'] as String?,
        callbackTime: json['callbackTime'] as String?,
        district: json['district'] as String?,
        country: json['country'] as String?,
        street: json['street'] as String?,
        speed: json['speed'] as num?,
        latitude: json['latitude'] as String?,
        city: json['city'] as String?,
        streetNumber: json['streetNumber'] as String?,
        bearing: json['bearing'] as num?,
        accuracy: json['accuracy'].toString(),
        adCode: json['adCode'] as String?,
        altitude: json['altitude'] as num?,
        locationType: json['locationType'] as num?,
        longitude: json['longitude'] as String?,
        cityCode: json['cityCode'] as String?,
        address: json['address'] as String?,
        description: json['description'] as String?,
      );

  Map<String, dynamic> toJson() => {
        'locTime': locTime,
        ' province': province,
        ' callbackTime': callbackTime,
        ' district': district,
        ' country': country,
        ' street': street,
        ' speed': speed,
        ' latitude': latitude,
        ' city': city,
        ' streetNumber': streetNumber,
        ' bearing': bearing,
        ' accuracy': accuracy,
        ' adCode': adCode,
        ' altitude': altitude,
        ' locationType': locationType,
        ' longitude': longitude,
        ' cityCode': cityCode,
        ' address': address,
        ' description': description,
      };
}
